package com.war.dao.outOfStorage;

import com.war.pojo.outofstorage.ProductOut;
import com.war.pojo.stock.DamagesInfo;
import com.war.pojo.stock.TransferInfo;
import com.war.pojo.system.Customer;
import com.war.pojo.system.Supplier;
import com.war.pojo.system.Warehouse;
import com.war.pojo.warehousing.PurchaseInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductOutDao {

    //查询
    @Select("select * from outofstorage_out")
    List<ProductOut> select();

    //录入
    @Insert("insert into outOfStorage_out (productName,unitPrice,unit,outAmount,outQuantity,outDate,clientName,clientTel,administrator,warehouseName,remarks)" +
            " value(#{productName},#{unitPrice},#{unit},#{outAmount},#{outQuantity},#{outDate},#{clientName},#{clientTel},#{administrator},#{warehouseName},#{remarks})")
    int add(ProductOut po);
    //根据id查询
    @Select("select * from outofstorage_out where outId=#{outId}")
    ProductOut selectByOutId(ProductOut po);

    @Select("SELECT number FROM outofstorage_out where name=#{warehouseName}")
    int storageNumNow(ProductOut po);

    //查询客户姓名
    @Select("select distinct(legal_person) from sys_customer")
    List<Customer> selectClientName();

    //查询客户电话
    @Select("select tel from sys_customer where legal_person=#{legal_person}")
    String getClientTel(Customer customer);

    //查询仓库名称
    @Select("select distinct(name) from sys_warehouse")
    List<Warehouse> selectWarehouseName();

    //查询仓库的管理员名称
    @Select("select manager from sys_warehouse where name=#{name}")
    String getAdministrator(Warehouse warehouse);
    //删除信息
    @Update("update outofstorage_out set status=0 where outId=#{outId}")
    int delInfo(ProductOut po);

    //根据产品名称查询
    @Select("select * from  outofstorage_out where productName=#{conValue} and status=1")
    List<ProductOut> selectByProductName(ProductOut po);
    //根据客户查询
    @Select("select * from  outofstorage_out where clientName=#{conValue} and status=1")
    List<ProductOut> selectByClientName(ProductOut po);
    //根据出库日期范围查询
    @Select("select * from  outofstorage_out where outDate between #{startDate} and #{endDate} and status=1\n"+
    "order by str_to_date(outDate,'%Y-%m-%d')")
    List<ProductOut> selectByDate(ProductOut po);
    //根据仓库名称查询
    @Select("select * from outofstorage_out where warehouseName=#{conValue}  and status=1")
    List<ProductOut> selectByWarehouseName(ProductOut po);
    //根据仓库管理员查询
    @Select("select * from outofstorage_out where administrator=#{conValue}  and status=1")
    List<ProductOut> selectByAdministrator(ProductOut po);

    //修改信息
    @Update("update outofstorage_out set productName=#{productName},unitPrice=#{unitPrice},unit=#{unit},outAmount=#{outAmount},outQuantity=#{outQuantity},outDate=#{outDate},clientName=#{clientName},clientTel=#{clientTel},administrator=#{administrator},warehouseName=#{warehouseName},remarks=#{remarks} where outId=#{outId}")
    int edit(ProductOut po);

    //批量删除
    @Delete("delete from outofstorage_out where outId=#{outId}")
    int delAll(ProductOut po);
    //退货
    @Insert("insert into outofstorage_return (outId,productName,returnDate,returnQuantity,returnReason,returnAmount,clientName,administrator,warehouseName)" +
            " value(#{outId},#{productName},#{returnDate},#{returnQuantity},#{returnReason},#{returnAmount},#{clientName},#{administrator},#{warehouseName})")
    int productReturn();
}

